package com.chapter.sample.redis.controller;

import com.chapter.sample.redis.answer.GeoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResult;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class GeoController {

    @Autowired
    private GeoService geoService;

    //添加坐标
    @RequestMapping("/geoadd")
    public String geoAdd(){
        return geoService.geoAdd();
    }

    //获取经纬度坐标geopost
    @RequestMapping("/geopos")
    public Point position(String member){
        return geoService.position(member);
    }

    //获取经纬度生成的bas32编码值geohash
    @RequestMapping("/geohash")
    public String hash(String member){
        return geoService.hash(member);
    }

    //获取两个位置直接的距离
    @RequestMapping("/geodist")
    public Distance distance(String member1,String member2){
        return geoService.distance(member2,member1);
    }

    //通过经纬度查找北京王府井附近的xxx
    @RequestMapping("/georadius")
    public GeoResults rediuByxy(){
        return geoService.rediuByxy();
    }

    //通过地方查找附近，本例写死天安门作为地址
    @RequestMapping("/georadiusByMember")
    public GeoResult radiusByMember(){
        return geoService.radiusByMember();
    }
}
